package com.fjnu.service.impl;

import com.fjnu.dao.TagDao;
import com.fjnu.entity.Tag;
import com.fjnu.service.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagDao tagDao;

    @Override
    public int addTag(Tag tag) {
        try {
            return tagDao.insert(tag);
        } catch (Exception e) {
            log.error("添加标签失败: {}", e.getMessage());
            throw new RuntimeException("添加标签失败", e);
        }
    }

    @Override
    public int deleteTag(Integer tagId) {
        try {
            return tagDao.delete(tagId);
        } catch (Exception e) {
            log.error("删除标签失败: {}", e.getMessage());
            throw new RuntimeException("删除标签失败", e);
        }
    }

    @Override
    public List<Tag> getAllTags() {
        try {
            return tagDao.selectAll();
        } catch (Exception e) {
            log.error("获取标签列表失败: {}", e.getMessage());
            throw new RuntimeException("获取标签列表失败", e);
        }
    }
}